<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('媒资列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                视频名：
                                <input type="text" name="title"/>
                            </li>

                            <li>
                                专辑名：
                                <input type="text" name="albumTitle"/>
                            </li>

                            <li>
                                类型：
                                <select name="type">
                                    <option value="">所有</option>
                                    <option value="1">电影</option>
                                    <option value="2">电视剧</option>
                                    <option value="3">动漫</option>
                                    <option value="4">体育</option>
                                    <option value="5">娱乐</option>
                                    <option value="6">游戏</option>
                                    <option value="9">纪录片</option>
                                    <option value="10">综艺</option>
                                    <option value="22">音乐</option>
                                    <option value="23">新闻</option>
                                    <option value="25">时尚</option>
                                    <option value="26">旅游</option>
                                    <option value="27">教育</option>
                                    <option value="28">科技</option>
                                    <option value="29">汽车</option>
                                    <option value="31">生活</option>
                                    <option value="50">合作</option>
                                    <option value="60">母婴</option>
                                    <option value="106">少儿</option>
                                    <option value="-1">未知</option>
                                </select>
                            </li>
                            <li>
                                状态：
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="0">待审核</option>
                                    <option value="1">审核中</option>
                                    <option value="2">已通过</option>
                                    <option value="-1">被驳回</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary multiple disabled" onclick="auditAll(1)" shiro:hasPermission="media:media:audit">
                    <i class="fa fa-edit"></i> 通过
                </a>
                <a class="btn btn-danger multiple disabled" onclick="auditAll(-1)" shiro:hasPermission="media:media:audit">
                    <i class="fa fa-remove"></i> 驳回
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="media:media:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var auditFlag = [[${@permission.hasPermi('media:media:audit')}]];
        var playClient = [[${playClient}]];
        var pcClientApi = ctx + "media/tencentInfo/sendUserInfo";
        var prefix = ctx + "media/media";
        var pic_hz_width = "755";  //1076
        var pic_hz_height = "425";  //608
        var pic_vt_width = "366";  //524
        var pic_vt_height = "515";  //736

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                auditUrl: prefix + "/audit",
                auditAllUrl: prefix + "/auditAll",
                modalName: "媒资",
                detailFormatter: detailFormatter,
                detailView: true,
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '媒资ID',
                    visible: false
                },
                {
                    field : 'vid', 
                    title : '腾讯vid',
                    visible: false
                },
                {
                    field : 'title', 
                    title : '视频名称'
//                    width: '10%',
//                    align: "left"
                },
                {
                    field : 'cid', 
                    title : '专辑id',
                    visible: false
                },
                {
                    field : 'albumTitle', 
                    title : '所属专辑'
                },
                {
                    field : 'description', 
                    title : '简介',
//                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field : 'langue', 
                    title : '语言'
                },
                {
                    field : 'leadingActor', 
                    title : '主演',
                    visible: false,
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
//                    width: '20%'
                },
                {
                    field : 'director', 
                    title : '导演',
                    visible: false
//                    width: '10%',
//                    align: "left"
                },
                {
                    field : 'year', 
                    title : '年份'
                },
                {
                    field : 'areaName', 
                    title : '地区'
                },
                {
                    field : 'score', 
                    title : '评分',
                    visible: false
                },
                {
                    field : 'type',
                    title : '类型',
                    formatter: function(value, row, index) {
                        if (value == '1') {
                            return '<span class="badge badge-danger">电影</span>';
                        } else if (value == '2') {
                            return '<span class="badge badge-danger">电视剧</span>';
                        } else if (value == '3') {
                            return '<span class="badge badge-danger">动漫</span>';
                        } else if (value == '4') {
                            return '<span class="badge badge-danger">体育</span>';
                        } else if (value == '5') {
                            return '<span class="badge badge-danger">娱乐</span>';
                        } else if (value == '6') {
                            return '<span class="badge badge-danger">游戏</span>';
                        } else if (value == '9') {
                            return '<span class="badge badge-danger">纪录片</span>';
                        } else if (value == '10') {
                            return '<span class="badge badge-danger">综艺</span>';
                        } else if (value == '22') {
                            return '<span class="badge badge-danger">音乐</span>';
                        } else if (value == '23') {
                            return '<span class="badge badge-danger">新闻</span>';
                        } else if (value == '25') {
                            return '<span class="badge badge-danger">时尚</span>';
                        } else if (value == '26') {
                            return '<span class="badge badge-danger">旅游</span>';
                        } else if (value == '27') {
                            return '<span class="badge badge-danger">教育</span>';
                        } else if (value == '28') {
                            return '<span class="badge badge-danger">科技</span>';
                        } else if (value == '29') {
                            return '<span class="badge badge-danger">汽车</span>';
                        } else if (value == '31') {
                            return '<span class="badge badge-danger">生活</span>';
                        } else if (value == '50') {
                            return '<span class="badge badge-danger">合作</span>';
                        } else if (value == '60') {
                            return '<span class="badge badge-danger">母婴</span>';
                        } else if (value == '106') {
                            return '<span class="badge badge-danger">少儿</span>';
                        } else if (value == '-1'){
                            return '<span class="badge badge-danger">未知</span>';
                        }
                    }
                },
                {
                    field : 'duration', 
                    title : '时长',
                    visible: false
                },
                {
                    field : 'episode', 
                    title : '当前集'
                },
                {
                    field : 'publishDate', 
                    title : '上映时间',
                    visible: false
                },
                {
                    field : 'url', 
                    title : '单视频播放url',
                    visible: false
                },
                {
                    field : 'picPath',
                    title : '海报',
                    formatter: function(value, row, index) {
                        // 图片预览（注意：如存储在本地直接获取数据库路径，如有配置context-path需要使用ctx+路径）
                        // 如：/profile/upload/2019/08/08/3b7a839aced67397bac694d77611ce72.png
                        return $.table.imageView(value,pic_hz_width,pic_hz_height);
                    }
                },
                {
                    field : 'status', 
                    title : '状态',
                    formatter: function(value, row, index) {
                        if (value == '0') {
                            return '<span class="badge badge-warning">待审核</span>';
                        } else if (value == '1') {
                            return '<span class="badge badge-success">审核中</span>';
                        } else if (value == '2') {
                            return '<span class="badge badge-primary">已通过</span>';
                        } else if (value == '-1') {
                            return '<span class="badge badge-danger">被驳回</span>';
                        }
                    }
                },
                {
                    title : '观看',
                    align : 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (playClient == 'PC'){
                            actions.push('<a href="javascript:void(0)" onclick="pcPlay(\'' + row.url  + '\')"><i class="fa fa-play-circle-o fa-2x"></i></a> ');
                        }else if (playClient == 'android'){
                            actions.push('<a href="javascript:void(0)" onclick="androidPlay(\'' + row.vid  + '\',\'' + row.cid  + '\',\'' + row.url  + '\')"><i class="fa fa-play-circle-o fa-2x"></i></a> ');
                        }
                        return actions.join('');
                    }
                },
                {
                    title: '审核',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.status != 2 && row.status != -1){
                            actions.push('<a class="btn btn-primary btn-xs ' + auditFlag + ' " href="javascript:void(0)" onclick="audit(\'' + row.id  + '\',\'' + 1  + '\')"><i class="fa fa-edit"></i>通过</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + auditFlag + '" href="javascript:void(0)" onclick="audit(\'' + row.id  + '\',\'' + -1  + '\')"><i class="fa fa-remove"></i>驳回</a> ');
                            return actions.join('');
                        }
                    }
                }]
            };
            $.table.init(options);
        });

        //展开显示
        function detailFormatter(index, row) {
            var html = [];
            $.each(row, function (key, value) {
                if (key != '0' && key != 'params') {
                    if ((key == 'picPath' || key == 'picPath') && $.common.isNotEmpty(value)) {
                        key = '海报';
                        html.push('<p><b>' + key + ':</b> <a class="btn btn-primary btn-xs" href="javascript:;" onclick="preview(\'' + key + '\', \'' + value + '\')"><i class="fa fa-image"></i>预览图片</a></p>');
                    } else {
                        if (value == null) {
                            value = '-';
                        }
                        if (key == 'searchValue'){
                            return;
                        }
                        if (key == 'createBy'){
                            return;
                        }
                        if (key == 'createTime'){
                            return;
                        }
                        if (key == 'updateBy'){
                            return;
                        }
                        if (key == 'updateTime'){
                            return;
                        }
                        if (key == 'remark'){
                            return;
                        }
                        if (key == 'teamId'){
                            return;
                        }
                        if (key == 'vid'){
                            key = '腾讯vid';
                        }
                        if (key == 'title'){
                            key = '视频名称';
                        }
                        if (key == 'cid'){
                            key = '专辑id';
                        }
                        if (key == 'albumTitle'){
                            key = '所属专辑';
                        }
                        if (key == 'description'){
                            key = '简介';
                        }
                        if (key == 'langue'){
                            key = '语言';
                        }
                        if (key == 'leadingActor'){
                            key = '主演';
                        }
                        if (key == 'director'){
                            key = '导演';
                        }
                        if (key == 'year'){
                            key = '年份';
                        }
                        if (key == 'areaName'){
                            key = '地区';
                        }
                        if (key == 'score'){
                            key = '评分';
                        }
                        if (key == 'type'){
                            key = '类型';
                            if (value == '1') {
                                value = '电影';
                            } else if (value == '2') {
                                value = '电视剧';
                            } else if (value == '3') {
                                value = '动漫';
                            } else if (value == '4') {
                                value = '体育';
                            } else if (value == '5') {
                                value = '娱乐';
                            } else if (value == '6') {
                                value = '游戏';
                            } else if (value == '9') {
                                value = '纪录片';
                            } else if (value == '10') {
                                value = '综艺';
                            } else if (value == '22') {
                                value = '音乐';
                            } else if (value == '23') {
                                value = '新闻';
                            } else if (value == '25') {
                                value = '时尚';
                            } else if (value == '26') {
                                value = '旅游';
                            } else if (value == '27') {
                                value = '教育';
                            } else if (value == '28') {
                                value = '科技';
                            } else if (value == '29') {
                                value = '汽车';
                            } else if (value == '31') {
                                value = '生活';
                            } else if (value == '50') {
                                value = '合作';
                            } else if (value == '60') {
                                value = '母婴';
                            } else if (value == '106') {
                                value = '少儿';
                            } else if (value == '-1'){
                                value = '未知';
                            }
                        }
                        if (key == 'duration'){
                            key = '时长';
                        }
                        if (key == 'episode'){
                            key = '当前集';
                        }
                        if (key == 'publishDate'){
                            key = '上映日期';
                        }
                        if (key == 'url'){
                            key = '播放地址';
                        }
                        if (key == 'picPath'){
                            key = '海报路径';
                        }
                        if (key == 'status'){
                            key = '状态';
                            if (value == '0'){
                                value = '待审核';
                            }else if (value == '1'){
                                value = '审核中';
                            }else if(value == '2'){
                                value = '审核通过';
                            }else if(value == '-1'){
                                value = '被驳回';
                            }
                        }
                        html.push('<div style="width:1080px;word-wrap:break-word"><p><b>' + key + ':</b>' + value + '</p></div>');
                    }
                }
            });
            return html.join('');
        }

        //海报预览
        function preview(key, path) {
            var size;
//            if (key == 'picPath') {
//                size = [0, 75, 92, 116, 130, 161, 175, 220, 260, 350, 450, 770];
//            }
//            if (key == 'picPath') {
//                size = [0, 120, 140, 160, 175, 226, 332, 408, 498, 556, 1920];
//            }
            size = [0, 120, 140, 160, 175, 226, 332, 408, 498, 556, 1920];
            var obj = {
                "status": 1,
                "msg": "",
                "title": "图片预览",
                "start": 0
            };
            var data = [];
            for (var i = 0; i < size.length; i++) {
                var picObj = {
                    'alt': size[i] + ".jpg",
                    'pid': i,
//                    'src': staticHost + path + '/' + size[i] + ".jpg",
                    'src': path,
                    'thumb': ""
                };
                data.push(picObj)
            }
            obj.data = data;
            layer.photos({
                photos: obj,
                anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
            });
        }

        // 批量审核
        function auditAll(auditState) {
            var auditConfirm;
            var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            if (auditState == 1){
                auditConfirm = "确认要通过选中的" + rows.length + "条数据吗?"
            }else if (auditState == -1){
                auditConfirm = "确认要驳回选中的" + rows.length + "条数据吗?"
            }
            $.modal.confirm(auditConfirm, function() {
                if (auditState == 1){
                    //批量通过
                    var url = $.table._option.auditAllUrl;
                    var data = { "ids": rows.join(),"auditState": auditState };
                    $.operate.submit(url, "post", "json", data);
                }else {
                    //批量驳回——填写驳回原因
                    $.modal.open("驳回原因", prefix + "/auditFailed/" + rows.join(),400,200);
                }
            });
        }

        // 单条审核
        function audit(id,auditState) {
            var auditConfirm;
            if (auditState == 1){
                auditConfirm = "确认要通过该条数据吗?"
            }else if (auditState == -1){
                auditConfirm = "确认要驳回该条数据吗?"
            }
            $.modal.confirm(auditConfirm, function() {
                //单条通过
                if (auditState == 1){
                    var url = $.table._option.auditUrl;
                    var data = { "id": id, "auditState": auditState };
                    $.operate.submit(url, "post", "json", data);
                }else {
                    //单条驳回——填写驳回原因
                    $.modal.open("驳回原因", prefix + "/auditFailed/" + id,400,200);
                }
            });
        }

        //调用android的播放
        function androidPlay(vid, cid, url) {
            var data = "{" + '"vid":' + '"'+ vid + '"' + "," + '"cid":' + '"' + cid + '"' + "," + '"url":' + '"' + url + '"' + "}";
            if (window.android) {
//            window.android.fullScreenPlay(data);
                window.android.playVideo(url,cid,vid);
            } else {
                alert("这不是Android设备");
                console.log(data);
            }
        }

        //PC端播放时掉调用接口
        function pcPlay(url){
            var data = { "url": url};
            $.operate.post(pcClientApi, data);
        }
    </script>
</body>
</html>